package com.atguigu.dga.governance.controller;

import com.atguigu.dga.governance.bean.GovernanceMetric;
import com.atguigu.dga.governance.service.GovernanceMetricService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 考评指标参数表 前端控制器
 * </p>
 *
 * @author tubage
 * @since 2024-03-16
 */
@RestController
@RequestMapping("/governanceMetric")
public class GovernanceMetricController {
    @Autowired
    GovernanceMetricService governanceMetricService;

    // 创建新记录
    @PostMapping("/createMetric")
    public ResponseEntity<?> createMetric(@RequestBody GovernanceMetric metricDTO) {
        GovernanceMetric metric = governanceMetricService.createMetric(metricDTO);
        return ResponseEntity.ok(metric);
    }

    // 根据metricCode获取记录
    @GetMapping("/getMetric")
    public List<GovernanceMetric> getMetricByCode(@RequestParam("metricCode") String metricCode) {
        List<GovernanceMetric> metricSingleList = governanceMetricService.getMetricByCode(metricCode);
        return metricSingleList;
    }

    // 获取所有指标
    @GetMapping("/getAllMetric")
    public List<GovernanceMetric> getAllMetric() {
        List<GovernanceMetric> metricList = governanceMetricService.list();
        return metricList;
    }

    // 更新记录
    @PostMapping("/disableOrNotMetric")
    public String updateMetric(@RequestParam(value="metricCode") String metricCode,
                               @RequestParam(value="isDisabled") Long isDisabled) {
        governanceMetricService.disableOrNotMetric( metricCode,  isDisabled);
        return "success";
    }

    @GetMapping("/deleteByMetricCode")
    public String deleteByMetricCode(@RequestParam("metricCode") String metricCode) {
        governanceMetricService.deleteByMetricCode(metricCode);
        return "success";
    }

    @PostMapping("/updateMetricByCode")
    public String updateMetricByCode(@RequestBody GovernanceMetric metricDTO) {
        governanceMetricService.updateMetricByCode(metricDTO);
        return "success";
    }



}
